/****************************************************************************************
**  File: Rectangle.hpp
**  Author: Asteroth
**  Date: 22/02/2009
****************************************************************************************/

#ifndef __RECTANGLE_HPP__
#define __RECTANGLE_HPP__

template <class T>
class Rectanglex {
public:
	T X, Y, W, H;

	Rectanglex():							X(0), Y(0), W(0), H(0) {}
	Rectanglex(const Rectanglex<T> &rect):	X(rect.X), Y(rect.Y), W(rect.W), H(rect.H) {}
	Rectanglex(T x, T y, T w, T h):			X(x), Y(y), W(w), H(h) {}

	inline Rectanglex<T> &operator = (const Rectanglex<T> &set) {
		X = set.X;
		Y = set.Y;
		W = set.W;
		H = set.H;
		return *this;
	}

	// Results a rectangle containing both
	inline Rectanglex<T> &operator += (const Rectanglex<T> &add) {
		T x = eMin(X, add.X);
		T y = eMin(Y, add.Y);
		W = eMax(X + W, add.X + add.W) - x;
		H = eMax(Y + H, add.Y + add.H) - y;
		X = x;
		Y = y;
		return *this;
	}

	// Results a rectangle containing both
	inline Rectanglex<T> operator + (const Rectanglex<T> &add) const {
		T x = eMin(X, add.X);
		T y = eMin(Y, add.Y);
		return Rectanglex<T>(x, y, eMax(X + W, add.X + add.W) - x, eMax(Y + H, add.Y + add.H) - y);
	}

	// Is inside: a[ b ]  ->  b inside a
	inline bool operator [] (const Vector2x<T> &vect) const {
		if (vect.X >= X && vect.Y >= Y && vect.X < X + W && vect.Y < Y + H)
			return true;
		return false;
	}

	// Is inside: a[ b ]  ->  b inside a
	inline bool operator [] (const Rectanglex<T> &rect) const  {
		if (rect.X >= X && rect.Y >= Y && rect.X + rect.W <= X + W && rect.Y + rect.H <= Y + H)
			return true;
		return false;
	}
};

typedef Rectanglex<float> Rectangle;
typedef Rectanglex<int> Rectanglei;

#endif
